package servlets;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import bdd.Connexion;
import bdd.DBLink;
import beans.ListeEnseignants;
import beans.ListeTypes;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author maboisba
 */
public class ListeEnseignantsServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String url = request.getRealPath("WEB-INF/prop.properties");
    out.println("DANS DOGET");
    ListeEnseignants listeEnseignants = new ListeEnseignants();
    listeEnseignants.recupererListeEnseignants();
    request.setAttribute("listeEnseignants", listeEnseignants);

    // On re-route l'appel vers la page d'accueil JSP
    gotoPage("/gestion_ec.jsp", request, response);
  }

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
       // try {
            response.setContentType("text/html;charset=UTF-8");
             PrintWriter out = response.getWriter();
            /*DBLink db = new DBLink();
            db.connexion();
            PreparedStatement pst = db.getConnection().prepareStatement("SELECT * FROM enseignant");

            ResultSet rs = pst.executeQuery();
            out.println("test1");
            while(rs.next()){
                out.println(rs.getString("nom"));
            }
            out.println("test2");
           
            String url = request.getRealPath("WEB-INF/prop.properties");*/

            ListeEnseignants listeEnseignants = new ListeEnseignants();
            listeEnseignants.recupererListeEnseignants();
            request.setAttribute("listeEnseignants", listeEnseignants);
            out.println("DANS DOPOST");
            // On re-route l'appel vers la page d'accueil JSP
            gotoPage("/gestion_ec.jsp", request, response);
        //} catch (SQLException ex) {
            //Logger.getLogger(ListeArticlesServlet.class.getName()).log(Level.SEVERE, null, ex);
        //}
          
  }

  private void gotoPage(String adress, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(adress);
    dispatcher.forward(request,response);
  }

}
